const { adminsModel } = require('./models/adminsModel');

// 管理员登录
module.exports.superLogin = async function (item) {
    const result = await adminsModel.findOne(item);
    return result;
}

// 增加管理员
module.exports.addNewAdmin = async function (item) {
    const result = await adminsModel.create(item);
    return result;
}

//注册判断
module.exports.isAdmins = async function (item) {
    const result = await adminsModel.find(item);
    return result;
}
//  获取管理员信息
module.exports.getAdmins = async function ({pagesize,currentpage}) {
    const result = await adminsModel.find().limit(pagesize-0+1).skip((currentpage-1)*(pagesize+1));
    const total = await adminsModel.countDocuments()
    return {result,total};
}

// 获取当前登录的ID
module.exports.getAdminsId = async function (_id) {
    const result = await adminsModel.findOne(_id);
    return result;
}

// 超级管理员修改密码
module.exports.updataAdminPassword = async function ({ password: newpassword, _id }) {
    const result = await adminsModel.updateOne({ _id }, { password: newpassword });
    return result;
}

// 禁用管理员
module.exports.frozenAdmin = async function (item) {
    const result = await adminsModel.updateOne({ _id: item._id }, { state: item.state });
    return result;
}